﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace YAPACS.RisServer.Services.ExtendCells;

/// <summary>
/// 多行单元格
/// </summary>
public class MultiRowCell : TextCell
{
    private readonly double _originalWidth = 0;

    /// <summary>
    /// 占位单元格
    /// </summary>
    [JsonProperty(PropertyName = "Style")]
    public JObject PlaceHolderContainer { get; set; }

    /// <summary>
    /// 原始宽度数据 weight
    /// </summary>
    public new double originalWidth { get; set; }

    /// <summary>
    /// 有参构造构造
    /// </summary>
    /// <param name="text"></param>
    /// <param name="width"></param>
    public MultiRowCell(string text, double width, int rowSpan,string textAlign) : base(text, width, rowSpan, textAlign)
    {
        ClassName = "row-span"; // 单元格跨行样式
        //Style.Add("position", "absolute"); //绝对位置
        Style["position"] = "absolute";
        originalWidth = width;
        SetPlaceHolder(); // 设置占位
    }


    /// <summary>
    /// 设置占位单元格
    /// 主要因为实际单元格position被设置为absolute后,脱离文档流导致原来的占位消失
    /// </summary>
    public void SetPlaceHolder()
    {
        PlaceHolderContainer = new JObject
        {
            { "type", "container" },
            { "isFixedHeight", true }
        };
        JObject placeHolderStyle = new()
        {
            { "height", "35px" },
            { "flexBasis", Width }
        };
        PlaceHolderContainer.Add("style", placeHolderStyle);
    }

}
